FROM maven:3.6.3-openjdk-8 as build
WORKDIR /app

COPY ./lib /app/lib

RUN mvn install:install-file -Dfile=lib/saas-java-linux-core.jar \
    -DgroupId=com.baidu.xchain \
    -DartifactId=baidu-xchain \
    -Dpackaging=jar \
    -Dversion=1.0.0

COPY pom.xml settings.xml ./

# 缓存 maven 依赖
RUN mvn -s ./settings.xml dependency:go-offline -B -DexcludeArtifactIds=baidu-xchain

COPY src src
RUN mvn -s ./settings.xml package

# 实际运行的容器
FROM openjdk:8-jre

ARG GIT_COMMIT=unspecified
ENV VERSION=${GIT_COMMIT}

COPY --from=build /app/target/*.jar /app/app.jar
COPY --from=build /app/lib/libSaasJavaSDK.so /app/lib/

ENTRYPOINT ["java", "-jar", "/app/app.jar"]